using System;
using System.ComponentModel.DataAnnotations;

namespace CommonApp
{
    public class DateRangeValidationAttribute : ValidationAttribute
    {
        public int MinYears { get; set; }
        public int MaxYears { get; set; }

        public override bool IsValid(object value)
        {
            if (!(value is DateTime))
                return false;

            var date = (DateTime)value;
            return DateTime.Now.AddYears(MinYears) <= date && date <= DateTime.Now.AddYears(MaxYears);
        }
    }
}
